<template>
  <el-dialog
    draggable
    overflow
    :title="titleMap[mode]"
    v-model="visible"
    :width="600"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <el-form
      :model="form"
      :rules="rules"
      ref="dialogForm"
      label-width="70px"
      label-position="right"
    >
      <sk-tabs type="border-card">
        <el-tab-pane ref="tab" label="调整唛头">
          <sc-VxeTable
            ref="xGrid1"
            :gridEvts="gridEvents"
            :gridOps="gridOps"
            :data="form.barcodes"
            :tablecode="'market_customer_barcode'"
          >
          </sc-VxeTable> </el-tab-pane
      ></sk-tabs>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script>
import skDicSelect from "@/components/skDicSelect";
import linkmanAdd from "./linkmanAdd";
import skAutoChoose from "@/components/skAutoChoose";
export default {
  emits: ["success", "closed"],
  components: { skDicSelect, skAutoChoose, linkmanAdd },
  data() {
    return {
      mode: "edit",
      gridEvents: {},
      gridOps: {
        height: 300,
      },
      titleMap: {
        add: "新增编辑",
        edit: "新增编辑",
      },
      form: {
        barcodes: [],
      },
      rules: {},
      visible: false,
      isSaveing: false,
    };
  },
  mounted() {},
  methods: {
    //显示
    open(mode = "add") {
      this.mode = mode;
      this.visible = true;

      return this;
    },

    //表单提交方法
    async submit() {
      this.isSaveing = true;
      var res = await this.$API.market.customerStorage.saveBarcode.post({
        barcodes: this.form.barcodes,
      });
      this.isSaveing = false;
      if (res.code == 200) {
        this.$emit("success", this.form, this.mode);
        this.visible = false;
        this.$message.success("操作成功");
      }
    },
    async getmain(ids) {
      this.$API.market.customerStorage.barcode.get({ ids }).then(res => {
        this.form.barcodes = res.data;
      });
    },
    //表单注入数据
    setData(data) {
      this.form.ids = data.map(v => v.id);
      this.getmain(this.form.ids);
    },
  },
};
</script>
